package ru.ntcreb.csir.libs.methods.SVCH;

import java.util.Map;

import ru.ntcreb.csir.libs.methods.SVCH.dto.SVCHImpulseDTO;
import ru.ntcreb.csir.libs.methods.SVCH.dto.TractDTO;
import ru.ntcreb.csir.libs.methods.SVCH.xml.XMLBuilderService;
import ru.ntcreb.csir.libs.methods.SVCH.xml.XMLParserService;

public class SVCHService {

	private final XMLParserService parserService = new XMLParserService();
	private final XMLBuilderService builderService = new XMLBuilderService();

	public SVCHImpulseDTO createSVCHImpulseDTO(double voltageAplitude_A,
			double impulseIncreaseConstant_Alpha,
			double impulseFallingConstant_Beta,
			double impulseFillingFrequency_U0) {
		SVCHImpulseDTO dto = new SVCHImpulseDTO();
		dto.setImpulseFallingConstant_Beta(impulseFallingConstant_Beta);
		dto.setImpulseFillingFrequency_U0(impulseFillingFrequency_U0);
		dto.setImpulseIncreaseConstant_Alpha(impulseIncreaseConstant_Alpha);
		dto.setVoltageAplitude_A(voltageAplitude_A);
		return dto;
	}

	// make configurable settings f.e max_iterations, time
	public native String createSVCHImpulseXML(String svchImpulseDTOXml);

	public Map<Double, Double> createSVCHImpulse(SVCHImpulseDTO svchImpulseDTO) {
		String svchImpulseDTOXml = builderService.createSVCHImpulseInputXML(
				svchImpulseDTO, null, null, null);
		String xml = createSVCHImpulseXML(svchImpulseDTOXml);
		return parserService.parseSVCHImpulseArray(xml);

	}

	public native String createTractSVCHReactionXML(String svchReactionInput);

	public Map<Double, Double> createTractSVCHReaction(
			Map<Double, Double> svchImpulseVoltageMap, TractDTO tract1,
			TractDTO tract2) {
		String svchReactionInput = builderService.createTractSVCHReactionInputXML(
				svchImpulseVoltageMap, tract1, tract2);
		String xml = createTractSVCHReactionXML(svchReactionInput);
		return parserService.parseSVCHImpulseReactionArray(xml);
	}

	public native double[] createTractSVCHFrequencyReactionXML(
			double[] svchImpulseVoltageArray, TractDTO tract1, TractDTO tract2);

}
